home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
ciarnv85.arc
/
UTIL.4TH
< prev
next >
Wrap
Text File
|
1986-04-08
|
3KB
|
98 lines
( UTIL.4TH This is a set of utilities canned in FORTH. )
HEX
: DI DECIMAL ;
( C" causes the following string, terminated by " to be stored in FORTH )
( memory and pointed to by the word following the closing quote. E. G. )
( C" b:file.4th" FPTR" )
( The above example creates a FORTH word, FPTR" which leaves the address )
( of the string "b:file.4th" on the stack. )
: C" 22 WORD DUP DUP C@ 1+ + 0 SWAP C! DUP C@ 2+ ALLOT 1+ CONSTANT ;
: CTAG CR ==>FH
IF ." TAG " ==>FN ZTYPE ." LINE# " BASE @ A BASE ! ==>L# @ . BASE !
THEN LATEST ID. ;
( This word vectors PAGE to clear the screen using ANSI escape codes. )
: <MPAGE> 1B EMIT ." [2J" ; ' <MPAGE> CFA 'PAGE !
: ?TERM 600 0 0 FF 21 INTCALL FF AND ; ( gets a char from keyboard )
: ?KEY ?TERM ABORT" STOPPED. " ; ( checks for and aborts if any key hit )
ASSEMBLER DEFINITIONS
: IFB 73 C, 0 C, HERE RESET ;
: IFA 76 C, 0 C, HERE RESET ;
FORTH DEFINITIONS
( INVOKE THE DOS COMMAND PROCESSOR FOR THE GIVEN ZERO STRING )
CODE DOSEXEC
AX, CS MOV
ES, AX MOV
BX, # 1800 MOV
AX, # 4A00 MOV
INT21 ( RELEASE ALL BUT 1800H PARAGRAPHS )
AX, CS MOV
ES, AX MOV
BX POP
DX POP
AX, # 4B00 MOV
SI PUSH
BP PUSH
80 , SP MOV
INT21
AX, CS MOV
DS, AX MOV
SS, AX MOV
SP, 80 MOV
BP POP
SI POP
NEXT JMP END-CODE
CODE DSEGMENT ( RETURNS FORTHS CODE SEGMENT ADDR )
AX, DS MOV
AX PUSH
NEXT JMP END-CODE
CODE LCMOVE BX, SI MOV CX POP DI POP ES POP SI POP DS POP
REPZ BYTE MOVS AX, CS MOV DS, AX MOV ES, AX MOV
SI, BX MOV NEXT JMP END-CODE
FORTH
C" COMMAND.COM" DOSCMD
( The FORTH word DOS followed by any MS-DOS command will invoke that )
( command. Afterwards, you are returned to FORTH. )
: DOS 0 WORD DUP C@ 1+ OVER C! DUP C@ OVER + 0D SWAP C!
DUP DUP 3 + OVER C@ 1+ <CMOVE DUP C@ 2F03 + OVER ! 2043 OVER 2+ !
84 ! DSEGMENT 86 ! ( PARM LINE ADDR )
5C 88 ! DSEGMENT 8A ! ( FCB 1 )
6C 8C ! DSEGMENT 8E ! ( FCB 2 )
2C @ 82 ! ( ENVIRONMENT )
DOSCMD 82 DOSEXEC ;
( The word FEMITO will open a file and vector the word EMIT so that )
( anything that is emitted to the screen will also be written to that )
( file until the word FEMITC which closes the file opened by FEMITO. )
CREATE FHAND 0 ,
VARIABLE 'FEMIT
CREATE CSUM 0 ,
: FEMIT FHAND @ OVER FPUTC 'FEMIT @ EXECUTE ;
: FEMITO FHAND @ ABORT" : FEMITO ALREADY OPEN "
1 FOPEN ?DUP ( FEMITO EXPECTS FILE NAME PTR )
IF FHAND ! 'EMIT @ 'FEMIT !
[ ' FEMIT CFA ] LITERAL 'EMIT !
ELSE 1 ABORT" FILE WONT OPEN FEMITO "
THEN ;
: FEMITC FHAND @ DUP
IF DUP 1A FPUTC FCLOSE 'FEMIT @ 'EMIT !
ELSE DROP
THEN ;
: FCREAT ( FNAME PMODE -- FPTR ) ( creates a file )
( RETURNS 0 IF IT FAILS, IOERR HAS ERROR # )
0 ROT ROT 3C00 DCALL
IF 0 ELSE 0 SWAP THEN IOERR ! ;